﻿namespace EFS.RC.CommunicatorContext.Common
{
	public static class Main
	{
		/// LyncConversationKeepAliveMillisecondsInterval
		public const System.Int32 LyncConversationKeepAliveMillisecondsInterval = 1000;

		public const System.Int32 MillisecondsBetweenRepetitiveAsyncCalls = 30;

		/// Enum OperatorType
		public enum OperatorType
		{
			NotSet,
			Agent,
			Supervisor
		}

		#region Properties
		/// Property HostFullUrl: Get
		public static System.String HostFullUrl
		{
			get
			{
				// crete url
				System.Text.StringBuilder sbUrl = new System.Text.StringBuilder();
				sbUrl.AppendFormat("{0}://{1}:{2}",
					System.Windows.Application.Current.Host.Source.Scheme,
					System.Windows.Application.Current.Host.Source.Host,
					System.Windows.Application.Current.Host.Source.Port);

				// ok
				return sbUrl.ToString();
			}
		}
		#endregion

		#region Utilities
		public static void ViewScoreExternal(
			System.Guid conversationGuid,
			System.Int32 surveyId)
		{
			// crete url
			System.Text.StringBuilder sbUrl = new System.Text.StringBuilder();
			sbUrl.AppendFormat("{0}/index.aspx?cmd=score_ext&cnv_guid={1}&srv_id={2}",
				HostFullUrl,
				conversationGuid,
				surveyId);

			// open
			System.Windows.Browser.HtmlPage.Window.Navigate(
				new System.Uri(sbUrl.ToString()),
				"__blank",
				"fullscreen=no,status=yes,toolbar=no,location=yes,menubar=no,directories=no,resizable=yes,scrollbars=yes");
		}

		/// Shows an error message
		public static void ShowErrorMessage(System.String error)
		{
			System.Windows.MessageBox.Show(error, "Error", System.Windows.MessageBoxButton.OK);
		}

		/// Shows an error message
		public static void ShowErrorMessage(
			System.String customError,
			System.Exception ex)
		{
			// create builder
			System.Text.StringBuilder sbErr = new System.Text.StringBuilder();
			sbErr.Append(customError);

			// test ex
			if (null != ex && EFS.Common.Verify.String(ex.Message))
			{
				sbErr.AppendFormat("{0}{0}{1}",
					System.Environment.NewLine,
					ex.Message);
			}

			// show
			System.Windows.MessageBox.Show(sbErr.ToString(), "Error", System.Windows.MessageBoxButton.OK);
		}

		/// ShowSuccessMessage
		public static void ShowSuccessMessage(System.String message)
		{
			System.Windows.MessageBox.Show(message, "Operation completed", System.Windows.MessageBoxButton.OK);
		}
		#endregion
	}

}